package user;

import java.io.FileOutputStream;
import java.io.IOException;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.sparql.vocabulary.FOAF;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;

public class FOAFGenerator {

	/**
	 * @param args
	 * @throws IOException 
	 */
	private void generate() throws IOException {
		Model model = ModelFactory.createDefaultModel();
		model.setNsPrefix("foaf", FOAF.NS);
		
		Resource individual = model.createResource("http://www.doc.ic.ac.uk/~dz309/");
		// static basic information 
		individual.addProperty(RDF.type, FOAF.Person)
			.addProperty(FOAF.title, "Mr")
			.addProperty(FOAF.firstName, "Donghua")
			.addProperty(FOAF.surname, "Zhang")
			.addProperty(FOAF.nick, "Leo")
			.addProperty(FOAF.gender, "male")
			.addProperty(FOAF.birthday, "03-07-1987")
			.addProperty(FOAF.msnChatID, "neverleo@live.cn")
			.addProperty(FOAF.mbox_sha1sum, "0d19b87bea1870ae2839413adcd2d4719f2938b7")
			.addProperty(FOAF.img, model.createResource("http://picasaweb.google.co.uk/lh/photo/SR2SPrJGHZg8jqcA0-cr0Q?feat=directlink"))
			.addProperty(FOAF.schoolHomepage, model.createResource("http://www.doc.ic.ac.uk/~dz309/"));

		// social relationship
		individual.addProperty(FOAF.knows, model.createResource().addProperty(RDF.type, FOAF.Person)
				.addProperty(FOAF.firstName, "Francesco")
				.addProperty(FOAF.surname, "Toni")
				.addProperty(FOAF.mbox_sha1sum, "45cdb341306722d7443bb15cf05634f15b1a1532")
				.addProperty(RDFS.seeAlso, model.createResource("http://www.doc.ic.ac.uk/~ft/")));
		
		// interest
		individual.addProperty(FOAF.interest, "snooker;auto;travel;internet");
		
		// WRITE THE RDF MODEL TO THE CONSOLE AS RDF/XML
		model.write(System.out, "RDF/XML-ABBREV");
		FileOutputStream out = new FileOutputStream("foaf.rdf", false);
		model.write(out, "RDF/XML-ABBREV");
		System.out.println("\nFOAF profile generated.");
	}
	
	
	public static void main(String[] args) {
		try {
			new FOAFGenerator().generate();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
